<script setup>
import { ref, onMounted } from 'vue'
import axios from "axios"
import CodeHighlight from '@/components/CodeHighlight.vue'
import RadarChart from '@/components/RadarChart.vue'

const isRemark = ref(true)
const adviceList = ref([])

onMounted(async () => {
  try {
    const response = await axios.get('/aiAdvice.json')
    adviceList.value = response.data.data
  } catch (error) {
    console.error('获取建议数据失败:', error)
    adviceList.value = [
      { index: '1', advice: '函数这样写，效果更好呢...' },
      { index: '2', advice: 'break是打错了吗,没有这个语法呢' }
    ]
  }
})
</script>

<template>
  <page-container title="运行结果">
    <el-row :gutter="30">
      <el-col :span="12">
        <div class="section-card">
          <h2 class="section-title">源代码</h2>
          <CodeHighlight />
        </div>
      </el-col>
      
      <el-col :span="12">
        <div class="section-card evaluation-card">
          <h2 class="section-title">AI评价</h2>
          <div class="evaluation-content">
            <div class="tab-switcher">
              <el-button 
                :type="isRemark ? 'primary' : 'default'" 
                @click="isRemark = true"
                size="small"
                class="tab-btn"
              >
                雷达图
              </el-button>
              <el-button 
                :type="!isRemark ? 'primary' : 'default'" 
                @click="isRemark = false"
                size="small"
                class="tab-btn"
              >
                详细评分
              </el-button>
            </div>
            
            <!-- 固定高度的显示区域 -->
            <div class="evaluation-display" :style="{ height: '320px' }">
              <div v-if="isRemark" class="radar-wrapper">
                <RadarChart />
              </div>
              <div v-else class="score-detail">
                <div class="total-score">
                  <h3>综合评分</h3>
                  <div class="score-circle">
                    <span class="score-number">63</span>
                    <span class="score-total">/100</span>
                  </div>
                </div>
                <div class="score-breakdown">
                  <div class="score-item">
                    <span class="score-label">语法评分</span>
                    <div class="score-bar">
                      <el-progress 
                        :percentage="70" 
                        :show-text="false"
                        color="#67C23A"
                      />
                      <span class="score-value">70/100</span>
                    </div>
                  </div>
                  <div class="score-item">
                    <span class="score-label">风格评分</span>
                    <div class="score-bar">
                      <el-progress 
                        :percentage="80" 
                        :show-text="false"
                        color="#E6A23C"
                      />
                      <span class="score-value">80/100</span>
                    </div>
                  </div>
                  <div class="score-item">
                    <span class="score-label">逻辑评分</span>
                    <div class="score-bar">
                      <el-progress 
                        :percentage="40" 
                        :show-text="false"
                        color="#F56C6C"
                      />
                      <span class="score-value">40/100</span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div class="section-card advice-section">
          <h2 class="section-title">改进建议</h2>
          <div class="advice-list">
            <div 
              v-for="(item, index) in adviceList" 
              :key="index"
              class="advice-item"
            >
              <span class="advice-index">{{ item.index || index + 1 }}</span>
              <span class="advice-text">{{ item.advice }}</span>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
  </page-container>
</template>

<style lang="scss" scoped>
.section-card {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  border: 1px solid #e4e7ed;
}

.evaluation-card {
  .section-title {
    margin-bottom: 16px;
  }
}

.section-title {
  color: #303133;
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f0f2f5;
}

.evaluation-content {
  .tab-switcher {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    
    .tab-btn {
      flex: 1;
      border-radius: 6px;
    }
  }
}

.evaluation-display {
  position: relative;
  min-height: 300px;
  
  .radar-wrapper {
    height: 100%;
    width: 100%;
  }
}

.score-detail {
  display: flex;
  gap: 40px;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 20px 0;
  
  .total-score {
    text-align: center;
    flex-shrink: 0;
    
    h3 {
      margin-bottom: 16px;
      color: #606266;
      font-size: 16px;
      font-weight: 500;
    }
    
    .score-circle {
      background: linear-gradient(135deg, #409EFF, #67C23A);
      border-radius: 50%;
      width: 120px;
      height: 120px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      color: white;
      box-shadow: 0 4px 12px rgba(64, 158, 255, 0.3);
      
      .score-number {
        font-size: 32px;
        font-weight: bold;
        line-height: 1;
      }
      
      .score-total {
        font-size: 14px;
        opacity: 0.9;
      }
    }
  }
  
  .score-breakdown {
    flex: 1;
    max-width: 280px;
    
    .score-item {
      margin-bottom: 24px;
      
      .score-label {
        display: block;
        margin-bottom: 8px;
        color: #606266;
        font-size: 14px;
        font-weight: 500;
      }
      
      .score-bar {
        display: flex;
        align-items: center;
        gap: 16px;
        
        .el-progress {
          flex: 1;
        }
        
        .score-value {
          font-size: 14px;
          color: #909399;
          min-width: 60px;
          text-align: right;
          font-weight: 500;
        }
      }
    }
  }
}

.advice-section {
  .advice-list {
    .advice-item {
      display: flex;
      align-items: flex-start;
      padding: 16px 0;
      border-bottom: 1px solid #f0f2f5;
      
      &:last-child {
        border-bottom: none;
      }
      
      .advice-index {
        background: #409EFF;
        color: white;
        border-radius: 4px;
        width: 28px;
        height: 28px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
        margin-right: 16px;
        flex-shrink: 0;
        margin-top: 2px;
        font-weight: 500;
      }
      
      .advice-text {
        color: #606266;
        line-height: 1.6;
        flex: 1;
        font-size: 14px;
        padding-top: 4px;
      }
    }
  }
}

// 确保雷达图容器正确显示
:deep(.radar-chart-container) {
  height: 100%;
  
  .vue-echarts {
    width: 100% !important;
    height: 100% !important;
  }
}

:deep(.el-progress-bar) {
  padding-right: 0;
}

:deep(.el-progress-bar__inner) {
  transition: all 0.3s ease;
  border-radius: 4px;
}

:deep(.el-progress-bar__outer) {
  border-radius: 4px;
}
</style>